package com.gitee.wsl.struct.command.model.parameters.arguments

import com.gitee.wsl.struct.command.internal.BadParameterValue
import com.gitee.wsl.struct.command.context.Context
import com.gitee.wsl.struct.command.model.parameters.TransformContext
import com.gitee.wsl.struct.command.model.parameters.arguments.Argument

/** A receiver for argument transformers. */
class ArgumentTransformContext(
    /** The argument that was invoked */
    val argument: Argument,
    override val context: Context,
) : Argument by argument, TransformContext {
    override fun fail(message: String): Nothing = throw BadParameterValue(message, argument)

    /** If [value] is false, call [fail] with the output of [lazyMessage] */
    inline fun require(value: Boolean, lazyMessage: () -> String = { "" }) {
        if (!value) fail(lazyMessage())
    }
}

